
<template>
  <div class="cjwz_box">
    <headercom></headercom>
    <div class="bcg">
      <div class="hedlist">
        <div class="headbtn">
          <a-button type="primary">
            <router-link to="../cjwzym">创建网站</router-link>
          </a-button>
        </div>
        <div class="seach">
          <div class="sele">
            <a-input placeholder="请输入企业ID/公司名称 " style="width: 250px" @change="onSearch" />
            <a-icon type="search" class="search" />
          </div>
        </div>
      </div>
      <div class="cjwz">
        <div class="hydj" v-if="$store.state.tjwz">
          <fbxjym class="hydj_xgym"></fbxjym>
        </div>

        <a-table
          :pagination="pagination"
          :scroll="{ x: 3200}"
          :columns="columns"
          :dataSource="data"
          bordered
          @change="getsiteAdminList"
        >
          <template
            v-for="col in ['kctype','domainName','userDomainName','appid','secret','samplebrand','sample','baidu_key','baidu_secret']"
            :slot="col"
            slot-scope="text, record, index"
          >
            <div :key="col" :title="text">
              <div class="xhcheck" v-if="col=='kctype'">
                <a-checkbox-group @change="checkChange" :defaultValue="record.kctype">
                  <a-row>
                    <a-col>
                      <a-checkbox value="导入">导入</a-checkbox>
                    </a-col>
                    <a-col>
                      <a-checkbox value="软件">软件</a-checkbox>
                    </a-col>
                    <a-col>
                      <a-checkbox value="寄售_导入">寄售_导入_客户商城</a-checkbox>
                    </a-col>
                  </a-row>
                </a-checkbox-group>
              </div>
              <!-- <a-date-picker
                v-if="col=='datetime'"
                @change="e => handleChange(moment(e).format('YYYY-MM-DD'), record.key, col)"
                :defaultValue="moment(text, dateFormat)"
              />-->
              <!-- :defaultValue="moment(text, dateFormat)" -->
              <a-input
                v-else-if=" col=='domainName'||'userDomainName'|| col=='appid'|| col=='secret'||col=='baidu_key'||col=='baidu_secret'  "
                :value="text"
                style="margin: -5px 0;width:150px;"
                @change="e => handleChange(e.target.value, record.key, col)"
              />

              <a-input
                v-else-if=" col=='sample'||col=='samplebrand' "
                :value="text"
                style="margin: -5px 0;width:350px;"
                @change="e => handleChange(e.target.value, record.key, col)"
              />
              <!-- <a-select
                v-else-if="record.editable&&col=='template'"
                showSearch
                placeholder="请选择模板号"
                optionFilterProp="children"
                style="width: 200px"
                :allowClear="true"
                v-model="template"
                @change="csbj"
                :filterOption="false"
              >
                <a-select-option value="temlate01">temlate01</a-select-option>
                <a-select-option value="temlate02">temlate02</a-select-option>
                <a-select-option value="temlate03">temlate03</a-select-option>
                <a-select-option value="temlate04">temlate04</a-select-option>
                <a-select-option value="temlate05">temlate05</a-select-option>
                <a-select-option value="temlate06">temlate06</a-select-option>
              </a-select>-->

              <template v-else>{{text}}</template>
            </div>
          </template>
          <template
            v-for="titletext in ['Name', 'enName', 'ruName','dwName','jaName']"
            :slot="titletext"
            slot-scope="text, record, index"
          >
            <div :key="titletext">
              <!-- Name   dwName enName  jaName ruName -->
              <a-switch
                v-if="titletext=='Name'"
                :defaultChecked="data[index].Name==0?false:true"
                @change="onChangeSwit(index,record,record.Name,'Name')"
              />
              <!-- <span v-if="titletext=='Cn'&&data[index].Name!=0">翻译</span> -->
              <a-switch
                v-if="titletext=='enName'"
                :defaultChecked="data[index].enName==0?false:true"
                @change="EnSwit(index, record,record.enName, 'enName')"
              />
              <!-- <span v-if="titletext=='En'&&data[index].enName!=0">翻译</span> -->
              <a-button
                class="fybtn"
                type="primary"
                size="small"
                v-if="titletext=='enName'&&data[index].enName!=0"
                @click="fysub(1,record.sqdwid)"
              >翻译</a-button>

              <a-switch
                v-if="titletext=='dwName'"
                :defaultChecked="data[index].dwName==0?false:true"
                @change="GmSwit(index,record, record.dwName,'dwName')"
              />
              <a-button
                class="fybtn"
                type="primary"
                size="small"
                v-if="titletext=='dwName'&&data[index].dwName!=0"
                @click="fysub(2,record.sqdwid)"
              >翻译</a-button>
              <!-- <span v-if="titletext=='Gm'&& data[index].dwName!=0">翻译</span> -->

              <a-switch
                v-if="titletext=='jaName'"
                :defaultChecked="data[index].jaName==0?false:true"
                @change="JpSwit(index,record, record.jaName,'jaName')"
              />
              <a-button
                class="fybtn"
                type="primary"
                size="small"
                :data-id="data[index].jaName"
                v-if="titletext=='jaName'&&data[index].jaName!=0"
                @click="fysub(3,record.sqdwid)"
              >翻译</a-button>

              <a-switch
                v-if="titletext=='ruName'"
                :defaultChecked="data[index].ruName==0?false:true"
                @change="RlSwit(index,record, record.ruName,'ruName')"
              />
              <a-button
                class="fybtn"
                type="primary"
                size="small"
                v-if="titletext=='ruName'&&data[index].ruName!=0"
                @click="fysub(4,record.sqdwid)"
              >翻译</a-button>
            </div>
          </template>
          <template slot="operation" slot-scope="text, record, index">
            <!-- <router-link v-if="czflg" to="/sjgl" class="del">数据管理</router-link> -->
            <span>
              <a class="del" @click="() => save(record,record.key)">保存</a>
              <a-popconfirm title="确认取消吗?" @confirm="() => cancel(record.key)">
                <!-- <a class="del">取消</a> -->
              </a-popconfirm>
            </span>
            <!-- <span v-else>
              <a class="del" @click="() => edit(record,record.key)">修改</a>
            </span>-->
            <a class="del" @click="() => rushcacho(record,record.key)">清缓存</a>

            <!-- <a class="del" v-if="czflg">关闭</a> -->
              <a href="javascript:;" class="del" @click="basicsclick(record,record.key)">基础设置</a>

          </template>
        </a-table>
        <div class="gl_tjwz" v-if="$store.state.bjlstk">
          <!-- <bjlstk class=""></bjlstk> -->
          <div class="gl_tjym bjtk">
            <div class="bjtk_list">
              <div class="head">
                <span></span>
                <a-button class="editable-add-btn" @click="close">
                  <a-icon type="close" />
                </a-button>
              </div>
              <a-table :pagination="false" :dataSource="dataSource" :columns="columnstk"></a-table>
            </div>
          </div>
        </div>
      </div>
      <!-- 基础设置弹框 -->
      <basicsettings v-if="set_flag"></basicsettings>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import qs from "qs";
import headercom from "../header-comm/header.vue";
import fbxjym from "../fbxj/fbxjym.vue";
import basicsettings from "./Basicsettings.vue";

const columns = [
  {
    title: "企业ID ",
    dataIndex: "sqdwid"
  },
  {
    title: "公司名称 ",
    dataIndex: "gsmc"
  },

  {
    title: "网站版本",
    dataIndex: "siteClass",
    scopedSlots: { customRender: "siteClass" }
  },
  // {
  //   title: "FTP",
  //   dataIndex: "ftp",
  //   scopedSlots: { customRender: "ftp" }
  // },
  {
    title: "现货",
    dataIndex: "kctype",
    scopedSlots: { customRender: "kctype" },
    width: 400
  },
  {
    title: "域名",
    dataIndex: "domainName",
    scopedSlots: { customRender: "domainName" }
  },
  {
    title: "后台域名",
    dataIndex: "userDomainName",
    scopedSlots: { customRender: "userDomainName" }
  },

  {
    title: "中文",
    dataIndex: "Name",
    scopedSlots: { customRender: "Name" }
  },
  {
    title: "英文",
    dataIndex: "enName",
    scopedSlots: { customRender: "enName" }
  },
  {
    title: "俄文",
    dataIndex: "ruName",
    scopedSlots: { customRender: "ruName" }
  },
  {
    title: "德文",
    dataIndex: "dwName",
    scopedSlots: { customRender: "dwName" }
  },
  {
    title: "日文",
    dataIndex: "jaName",
    scopedSlots: { customRender: "jaName" }
  },
  {
    title: "综合样本品牌",
    dataIndex: "samplebrand",
    scopedSlots: { customRender: "samplebrand" }
  },
  {
    title: "综合样本",
    dataIndex: "sample",
    scopedSlots: { customRender: "sample" }
  },
  {
    title: "小程序appid",
    dataIndex: "appid",
    scopedSlots: { customRender: "appid" }
  },
  {
    title: "小程序密钥",
    dataIndex: "secret",
    scopedSlots: { customRender: "secret" }
  },
  {
    title: "百度翻译key",
    dataIndex: "baidu_key",
    scopedSlots: { customRender: "baidu_key" }
  },
  {
    title: "百度翻译密钥",
    dataIndex: "baidu_secret",
    scopedSlots: { customRender: "baidu_secret" }
  },
  {
    title: "操作",
    dataIndex: "operation",
    width: 240,
    fixed: "right",
    scopedSlots: { customRender: "operation" }
  }
];
const data = [];

const plainOptions = ["导入", "软件"];
const defaultCheckedList = [];

export default {
  data() {
    this.cacheData = data.map(item => ({ ...item }));
    return {
      checkedList: defaultCheckedList,
      indeterminate: true,
      checkAll: false,
      plainOptions,
      serchvalue: "",
      data,
      columns,
      dateFormat: "YYYY/MM/DD",
      czflg: true,
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0
      },
      template: "",
      dataSource: [],
      count: 2,
      kctype: "",
      check_box: "默认",
      columnstk: [
        {
          title: "报价型号",
          dataIndex: "name",
          scopedSlots: { customRender: "name" }
        },
        {
          title: "品牌",
          dataIndex: "age"
        },
        {
          title: "报价公司",
          dataIndex: "gs"
        },
        {
          title: "报价联系人",
          dataIndex: "money"
        },
        {
          title: "手机",
          dataIndex: "date"
        },
        {
          title: "可供数量",
          dataIndex: "num"
        },
        {
          title: "价格",
          dataIndex: "jg"
        },
        {
          title: "备注",
          dataIndex: "bz"
        }
      ],
      set_flag:false,
      basicsvalue:'',
      
    };
  },
  methods: {
    moment,
    //搜索框
    onSearch(e) {
      this.serchvalue = e.target.value;
      this.getsiteAdminList(this.pagination, this.serchvalue);
    },
    csbj(value) {
      this.template = value;
    },
    checkChange(checkedValues) {
      var checked = checkedValues.filter(s => $.trim(s).length > 0);
      this.check_box = checked;
      this.kctype = checked;
      console.log(checked);
    },
    tempChange(value) {},
    dateChange(date, dateString) {},
    handleChange(value, key, column) {
      const newData = [...this.data];
      const target = newData.filter(item => key === item.key)[0];
      if (target) {
        target[column] = value;
        this.data = newData;
      }
    },
    edit(value, key) {
      this.template = value.template;
      const newData = [...this.data];
      this.czflg = false;
      const target = newData.filter(item => key === item.key)[0];
      if (target) {
        target.editable = true;
        this.data = newData;
      }
    },
    save(value, key) {
      console.log(value);
      const newData = [...this.data];
      const target = newData.filter(item => key === item.key)[0];
      if (target) {
        delete target.editable;
        this.data = newData;
        this.cacheData = newData.map(item => ({ ...item }));
        newData[0].template = this.template;
      }
      if (this.check_box == "默认") {
        this.kctype = value.kctype;
      }
      // date  ftp  domainName  template
      this.axios
        .post(
          "quanxian/siteAdminListEdit.php",
          qs.stringify({
            id_num: value.id_num,
            sqdwid: value.sqdwid,
            appid: value.appid,
            secret: value.secret,
            domainName: value.domainName,
            userDomainName: value.userDomainName,
            template: value.template,
            sample: value.sample,
            samplebrand: value.samplebrand,
            kctype: this.kctype,
            baidu_key: value.baidu_key,
            baidu_secret: value.baidu_secret
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.kctype = "";
            this.getsiteAdminList(this.pagination, this.serchvalue);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
      this.czflg = true;
    },
    basicsclick(value){
      this.basicsvalue=value
      this.set_flag=true
      console.log(this.basicsvalue)

    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    cancel(key) {
      const newData = [...this.data];
      const target = newData.filter(item => key === item.key)[0];
      if (target) {
        Object.assign(
          target,
          this.cacheData.filter(item => key === item.key)[0]
        );
        delete target.editable;
        this.data = newData;
      }
      this.czflg = true;
    },
    getsiteAdminList(pagination, serchvalue) {
      this.axios
        .post(
          "quanxian/siteAdminList.php",
          qs.stringify({
            page: pagination.current,
            pageSize: pagination.defaultPageSize,
            keywords: serchvalue
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.pagination.total = Number(res.data.result.total);
            for (var i = 0; i < res.data.result.data.length; i++) {
              res.data.result.data[i].key = res.data.result.data[i].id_num;
              res.data.result.data[i].kctype = res.data.result.data[
                i
              ].kctype.trim();
              res.data.result.data[i].kctype = res.data.result.data[
                i
              ].kctype.split("|");

              // for(var j=0;i<this.data[i].kctype.length;j++){
              //     if(this.data[i].kctype[j]!=""){
              //      this.data[i].kctype=this.data[i].kctype

              //  }
              // }
            }
            this.data = res.data.result.data;
            console.log(this.data);
          } else {
            this.data = [];
          }
        });
    },
    onCellChange(key, dataIndex, value) {
      const dataSource = [...this.dataSource];
      const target = dataSource.find(item => item.key === key);
      if (target) {
        target[dataIndex] = value;
        this.dataSource = dataSource;
      }
    },
    onDelete(key) {
      const dataSource = [...this.dataSource];
      this.dataSource = dataSource.filter(item => item.key !== key);
    },
    fbxj() {
      this.$store.state.tjwz = true;
    },
    close() {
      this.$store.state.bjlstk = false;
    },
    ///////////////////////////////////////
    //翻译
    fysub(index, value) {
      this.fyflag = true;
      this.axios
        .post(
          "set/lgTranslateAll.php",
          qs.stringify({
            lg: index,
            sqdwid: value
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.fyflag = false;
            this.$notification["success"]({
              message: "翻译成功",
              description: res.data.msg
            });
          }
        });
    },
    //开关
    clickswitch(id_num, sqdwid, textname, isOpen) {
      console.log(isOpen);
      this.axios
        .post(
          "quanxian/siteAdminListLgEdit.php",
          qs.stringify({
            id_num: id_num,
            sqdwid: sqdwid,
            lgType: textname,
            isOpen: isOpen
          })
        )
        .then(res => {
          console.log(res);
        });
    },
    onChangeSwit(index, value, record, text) {
      console.log(value);
      if (text == "Name" && record == "1") {
        this.data[index].Name = "0";
      } else {
        this.data[index].Name = "1";
      }
      this.clickswitch(value.id_num, value.sqdwid, text, value.Name);
    },
    EnSwit(index, value, record, text) {
      console.log(value);
      if (text == "enName" && record == "1") {
        this.data[index].enName = "0";
      } else {
        this.data[index].enName = "1";
      }
      this.clickswitch(value.id_num, value.sqdwid, text, value.enName);
    },
    GmSwit(index, value, record, text) {
      if (text == "dwName" && record == "1") {
        this.data[index].dwName = "0";
      } else {
        this.data[index].dwName = "1";
      }
      this.clickswitch(value.id_num, value.sqdwid, text, value.dwName);
    },
    JpSwit(index, value, record, text) {
      if (text == "jaName" && record == "1") {
        this.data[index].jaName = "0";
      } else {
        this.data[index].jaName = "1";
      }
      this.clickswitch(value.id_num, value.sqdwid, text, value.jaName);
    },
    RlSwit(index, value, record, text) {
      if (text == "ruName" && record == "1") {
        this.data[index].ruName = "0";
      } else {
        this.data[index].ruName = "1";
      }
      this.clickswitch(value.id_num, value.sqdwid, text, value.ruName);
    },
    rushcacho(value, key) {
      this.axios
        .post(
          "set/deleteCache.php",
          qs.stringify({
            sqdwid: value.sqdwid
          })
        )
        .then(res => {
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },

    creatwximg(value, key) {
      let domainName = value.domainName;
      this.axios
        .get("http://" + domainName + "/resetCache/deleteCache?updata=5655840!")
        .then(res => {
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    }
    ////////////////////////////////
  },
  components: {
    headercom,
    fbxjym,
    basicsettings
  },
  created() {
    this.getsiteAdminList(this.pagination);
  }
};
</script>

<style lang='less' >
th.column-money,
td.column-money {
  text-align: right !important;
}

.cjwz_box {
  width: 100%;
  .xhcheck {
    .ant-row {
      div {
        display: inline-block;
      }
    }
  }
  .seach {
    display: inline-block;
    .sele {
      position: relative;
      i {
        position: absolute;
        top: 22px;
        right: 8px;
      }
    }
  }
  .hedlist {
    position: relative;
    top: 65px;
    width: 98%;
    left: 1%;
    height: 60px;
    background-color: #fff;
    text-align: left;
    padding: 0 20px !important;
    display: flex;
    justify-content: space-between;
  }
  .cjwz {
    overflow: hidden;

    position: absolute;
    background-color: #fff;
    width: 98%;
    top: 140px;
    left: 1%;
    border: 1px solid #ccc;
    // box-shadow: 0px 0px 7px #ccc;
    .ant-checkbox-inner {
      // display: none!important;
    }

    .hydj {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      background: rgba(0, 0, 0, 0.5);
      z-index: 999;
      height: 930px;
      .hydj_xgym {
        position: absolute;
        width: 80%;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
  .gl_tjwz {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999999;
    height: 930px;
    .gl_tjym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}
.bjtk {
  position: absolute;
  z-index: 9999;
  width: 90%;
  height: auto;
  background-color: #fff;
  text-align: left;
  padding: 20px;
  top: 77px;
  left: 152px;
  .bjtk_list {
    .head {
      display: flex;
      justify-content: space-between;
    }
    .editable-cell {
      position: relative;
    }

    .editable-cell-input-wrapper,
    .editable-cell-text-wrapper {
      padding-right: 24px;
    }

    .editable-cell-text-wrapper {
      padding: 5px 24px 5px 5px;
    }

    .editable-cell-icon,
    .editable-cell-icon-check {
      position: absolute;
      right: 0;
      width: 20px;
      cursor: pointer;
    }

    .editable-cell-icon {
      line-height: 18px;
      display: none;
    }

    .editable-cell-icon-check {
      line-height: 28px;
    }

    .editable-cell:hover .editable-cell-icon {
      display: inline-block;
    }

    .editable-cell-icon:hover,
    .editable-cell-icon-check:hover {
      color: #108ee9;
    }

    .editable-add-btn {
      margin-bottom: 8px;
    }
  }
}
</style>
